﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace NinjaToolbox.PhysicsSystem
{
    [CreateAssetMenu(fileName = "PhysicsLayerMatrixScriptableConfigurator", menuName = "NinjaToolbox/PhysicsSystem/Physics Layer Matrix Scriptable Configurator")]
    public class PhysicsLayerMatrixScriptableConfigurator : ScriptableObject, IPhysicsLayerMatrix
    {
        [Serializable]
        public struct IsIntersect
        {
            public int layer1;
            public int layer2;
            public bool intersect;
        }

        public IsIntersect[] intersects;
        BitArray mInternalArray;


        bool IPhysicsLayerMatrix.IsIntersect(int layer1, int layer2)
        {
            return mInternalArray[layer1 + layer2 * 32];
        }

       public void Initialization()
        {
            mInternalArray = new BitArray(32 * 32);
            mInternalArray.SetAll(true);
            for (int i = 0; i < intersects.Length; i++)
            {
                var item = intersects[i];

                mInternalArray[item.layer1 + item.layer2 * 32] = item.intersect;
            }
        }
    }
}
